﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class manage_shouquanshezhi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (DataClassesDataContext ds = new DataClassesDataContext())
        {
            var r1 = (from q in ds.XiTongXinXiJiLu
                      where q.biaoti == "appid"
                      where q.neirong != null
                      where q.neirong != ""
                      select q).FirstOrDefault();
            if (r1 != null)
            {
                TextBox1.Text = r1.neirong.ToString();
            }


            var r2 = (from q in ds.XiTongXinXiJiLu
                      where q.biaoti == "appsecret"
                      where q.neirong != null
                      where q.neirong != ""
                      select q).FirstOrDefault();
            if (r2 != null)
            {
                TextBox2.Text = r1.neirong.ToString();
            }

            if (r1 != null && r2 != null)
            {
                HiddenFieldBianJi.Value = "edit";//标记编辑状态
            }
            else
            {
                HiddenFieldBianJi.Value = "insert";
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim() != "" && TextBox2.Text.Trim() != "")
        {
            using (DataClassesDataContext ds = new DataClassesDataContext())
            {
                if (HiddenFieldBianJi.Value == "edit")//编辑状态
                {
                    var r1 = (from q in ds.XiTongXinXiJiLu
                              where q.biaoti == "appid"
                              where q.neirong != null
                              where q.neirong != ""
                              select q).FirstOrDefault();

                    r1.neirong = TextBox1.Text.Trim();

                    var r2 = (from q in ds.XiTongXinXiJiLu
                              where q.biaoti == "appsecret"
                              where q.neirong != null
                              where q.neirong != ""
                              select q).FirstOrDefault();

                    r1.neirong = TextBox2.Text.Trim();

                    ds.SubmitChanges();

                }
                else//新增状态
                {
                    XiTongXinXiJiLu p1 = new XiTongXinXiJiLu();
                    p1.biaoti = "appid";
                    p1.neirong =TextBox1.Text.Trim();
                    p1.zhushi="公众平台申请自定义菜单使用的AppId";
                    ds.XiTongXinXiJiLu.InsertOnSubmit(p1);

                    XiTongXinXiJiLu p2 = new XiTongXinXiJiLu();
                    p2.biaoti = "appsecret";
                    p2.neirong = TextBox2.Text.Trim();
                    p2.zhushi = "公众平台申请自定义菜单使用的AppSecret";
                    ds.XiTongXinXiJiLu.InsertOnSubmit(p2);
                    ds.XiTongXinXiJiLu.InsertOnSubmit(p2);

                    ds.SubmitChanges();
                }
            }
        }
    }
}